package edu.dali.enterprise_test.service.classification.impl;

import com.github.pagehelper.Page;
import edu.dali.enterprise_test.dao.mapper.classification.SubMapper;
import edu.dali.enterprise_test.model.Pager;
import edu.dali.enterprise_test.model.vo.Dto;
import edu.dali.enterprise_test.service.classification.SubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubServiceImpl implements SubService {

    @Autowired
    private SubMapper subMapper;

    @Override
    public Pager<Dto> selectList(Dto dto) {
        Pager<Dto> p = new Pager<>();
        List<Dto> data = subMapper.selectList(dto);
        p.setData(data);
        int count = (int)((Page) data).getTotal();
        p.setCount(count);
        p.setMsg("");
        p.setCode(0);

        return p;
    }

    @Override
    public Dto selectOne(String id) {
        return subMapper.selectOne(id);
    }

    @Override
    public void update(Dto dto) {
        subMapper.update(dto);
    }

    @Override
    public void delete(String id) {
        subMapper.delete(id);
    }

    @Override
    public void insert(Dto dto) {
        subMapper.insert(dto);
    }
}
